home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Id: traversal_test.java,v 1.12 1996/10/03 19:46:51 hudson Exp $
- * $Author: hudson $
- */
-
- package sub_arctic.test;
-
- import sub_arctic.lib.interactor;
- import sub_arctic.lib.interactor_applet;
- import sub_arctic.lib.manager;
- import sub_arctic.lib.interactor_consts;
- import sub_arctic.lib.top_level;
- import sub_arctic.lib.base_parent_interactor;
- import sub_arctic.lib.button;
- import sub_arctic.lib.drag_icon;
- import sub_arctic.lib.std;
- import sub_arctic.lib.backdrop;
- import sub_arctic.lib.line_display;
- import sub_arctic.lib.row;
- import sub_arctic.lib.text_toggle_collection;
- import sub_arctic.lib.toggle;
- import sub_arctic.lib.icon;
- import sub_arctic.lib.interactor_pred;
- import sub_arctic.lib.traversal_xform;
- import sub_arctic.input.std_drag_filters;
- import sub_arctic.input.event;
- import sub_arctic.input.callback_object;
- import sub_arctic.input.pressable;
- import sub_arctic.input.move_draggable;
- import sub_arctic.input.pick_collector;
- import sub_arctic.output.style;
- import sub_arctic.output.style_manager;
- import sub_arctic.output.loaded_image;
- import sub_arctic.lib.sub_arctic_error;
-
- import java.awt.Point;
- import java.awt.Rectangle;
-
- public class traversal_test extends interactor_applet
- implements interactor_consts, callback_object {
-
- public static int setting = 0;
-
- /**
- * Shorthand for generating a button's image in the default style.
- */
- public static loaded_image[] std_label(String s) {
- style st=style_manager.current_style();
- return st.button_make_images(s,style_manager.default_font(),10,5,false);
- }
-
- public void callback(interactor from_obj, event evt, int cb_n, Object info)
- {
- int i = ((Integer)from_obj.user_info()).intValue();
- System.out.println("setting = " + (i-1));
- setting = i-1;
- }
-
- public void build_ui(base_parent_interactor top)
- {
- row r;
- String labels[] = {
- "\"Grab\" point", "Top-left", "Top-right", "Bottom-left",
- "Bottom-right", "Center"};
-
- /*** MOST OF THIS WE JUST STOLE FROM ANOTHER TEST... ***/
-
- r = new row(5, 5, true, false, row.CENTER_JUSTIFIED);
- top.add_child(r);
- r.add_child(new text_toggle_collection(labels, true, -1, this));
- ((toggle)(r.child(0).child(1))).set_cur_state(1);
-
- base_parent_interactor p1 = new base_parent_interactor(10,10,380,380);
- r.add_child(p1);
- p1.add_child(new backdrop(400,400,std.stipple25()));
-
- loaded_image[] lab1 = std_label("Traversal Test");
- xdrag_icon_t1 drag = new xdrag_icon_t1(10,10,lab1[0]);
- p1.add_child(drag);
-
- lab1 = std_label("Interactor Tree dumped to System.out");
- xdrag_icon_t2 drag2 = new xdrag_icon_t2(60,60,lab1[0]);
- p1.add_child(drag2);
-
- line_display ln = new line_display(50,50,250,50,0);
- p1.add_child(ln);
- ln = new line_display(50,50,50,150,0);
- p1.add_child(ln);
- ln = new line_display(250,50,250,150,0);
- p1.add_child(ln);
- ln = new line_display(50,150,250,150,0);
- p1.add_child(ln);
-
- ln = new line_display(0,p1.h()-20,p1.w()-10,p1.h()-20,0);
- p1.add_child(ln);
-
- ln = new line_display(p1.w()-10,0,p1.w()-10,p1.h()-20,0);
- p1.add_child(ln);
-
- ln = new line_display(10,300,350,20,0);
- p1.add_child(ln);
-
- lab1 = std_label("Traversal Test");
- xdrag_icon_t3 drag3 = new xdrag_icon_t3(10,300,lab1[0]);
- p1.add_child(drag3);
-
- lab1 = std_label("Traversal Test");
- xdrag_icon_t4 drag4 = new xdrag_icon_t4(200,10,lab1[0]);
- p1.add_child(drag4);
-
- /*** HERE IS THE ACTUAL TEST... ***/
-
- System.out.println("-----------------------------------------");
- System.out.println("Doing post-order traversal of entire tree");
- System.out.println("-----------------------------------------");
- pick_collector result = new pick_collector();
- top.traverse_and_collect(0, TRAV_POST, null, null, null, null, result);
- for (int i = 0; i < result.num_picks(); i++)
- System.out.println("-->" + result.pick(i).obj.tag_str());
-
- System.out.println("------------------------");
- System.out.println("Doing drawing order dump");
- System.out.println("------------------------");
- result.reset();
- interactor_pred print = new print_pred();
- traversal_xform incr_int = new incr_int_xform();
- top.traverse_and_collect(1, TRAV_DRAW, print, null, incr_int,
- new Integer(0), result);
-
- System.out.println("---------------------");
- System.out.println("Doing pick order dump");
- System.out.println("---------------------");
- result.reset();
- top.traverse_and_collect(1, TRAV_PICK, print, null, incr_int,
- new Integer(0), result);
-
- System.out.println("-----------------------------------------");
- System.out.println(
- "Doing drawing order dump pruning under text_toggle_collection");
- System.out.println("-----------------------------------------");
- result.reset();
- interactor_pred stop_at_ttc = new not_ttc_pred();
- top.traverse_and_collect(1, TRAV_DRAW, print, stop_at_ttc, incr_int,
- new Integer(0), result);
- }
- }
-
- class print_pred implements interactor_pred {
- public boolean test(interactor obj, Object parameters)
- {
- if (!(parameters instanceof Integer))
- throw new sub_arctic_error("Non integer parameter");
- int indent = ((Integer)parameters).intValue();
- for (int i=0; i<indent; i++)
- System.out.print(" ");
- System.out.println(obj.getClass().getName() + " " + obj.hashCode());
- return false;
- }
- }
-
- class incr_int_xform implements traversal_xform {
- public Object xform(
- Object parent_parameters,
- interactor child_obj,
- int child_index)
- {
- if (!(parent_parameters instanceof Integer))
- throw new sub_arctic_error("Non integer parameter");
- return new Integer(((Integer)parent_parameters).intValue() + 1);
- }
- }
-
- class not_ttc_pred implements interactor_pred {
- public boolean test(interactor obj, Object parameters)
- {
- return !(obj instanceof text_toggle_collection);
- }
- }
-
- class xdrag_icon_t1 extends icon implements pressable, move_draggable {
- public xdrag_icon_t1(int x, int y, loaded_image img)
- {super(x,y,img);}
- public int drag_feature_point()
- {
- return drag_limit_test.setting;
- }
- public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
- {
- return std_drag_filters.limit_to_parent(orig_pt,this,true,10,20, f_pt);
- }
- public boolean press(event evt, Object user_info)
- {
- manager.move_drag_focus.set_focus_to(this, evt, user_info);
- return true;
- }
- public boolean release(event evt, Object user_info)
- {
- return true;
- }
- public boolean drag_start(
- event evt, int xv, int yv, int gx, int gy, Object user_info)
- { return true; }
- public boolean drag_feedback(
- event evt,
- int x_pos, int y_pos,
- int start_x, int start_y,
- int grab_x, int grab_y,
- Object user_info)
- {
-
- /* move our position */
- set_pos(x_pos, y_pos);
- return true;
- }
- public boolean drag_end(
- event evt,
- int x_pos, int y_pos,
- int start_x, int start_y,
- int grab_x, int grab_y,
- Object user_info)
- {
- /* let drag_feedack to all the work */
- return drag_feedback(evt, x_pos, y_pos, start_x, start_y, grab_x, grab_y,
- user_info);
- }
- }
-
- class xdrag_icon_t2 extends xdrag_icon_t1 {
- public xdrag_icon_t2(int x, int y, loaded_image img)
- {super(x,y,img);}
- public static Rectangle r = new Rectangle(50,50, 200,100);
- public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
- {
- return std_drag_filters.limit_to_rect(orig_pt,r);
- }
- }
-
- class xdrag_icon_t3 extends xdrag_icon_t1 {
- public xdrag_icon_t3(int x, int y, loaded_image img)
- {super(x,y,img);}
- public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
- {
- return std_drag_filters.limit_to_line_seg(orig_pt, 10, 300, 350,20);
- }
- }
-
- class xdrag_icon_t4 extends xdrag_icon_t1 {
-
- public xdrag_icon_t4(int x, int y, loaded_image img)
- {super(x,y,img);}
-
- public boolean drag_start(
- event evt,
- int x, int y,
- int grab_x, int grab_y,
- Object user_info)
- {
- System.out.println("drag_start(evt, " +
- "x="+ x + "," + "y=" + y + "," +
- "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
- "user_info");
- return super.drag_start(evt,x,y,grab_x,grab_y,user_info);
- }
-
- public boolean drag_feedback(
- event evt,
- int x, int y,
- int start_x, int start_y,
- int grab_x, int grab_y,
- Object user_info)
- {
- System.out.println("drag_feedback(evt, " +
- "x="+ x + "," + "y=" + y + "," +
- "start_x="+ start_x + "," + "start_y=" + start_y + "," +
- "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
- "user_info");
- return
- super.drag_feedback(evt,x,y,start_x,start_y,grab_x,grab_y,user_info);
- }
-
- public boolean drag_end(
- event evt,
- int x, int y,
- int start_x, int start_y,
- int grab_x, int grab_y,
- Object user_info)
- {
- System.out.println("drag_end(evt, " +
- "x="+ x + "," + "y=" + y + "," +
- "start_x="+ start_x + "," + "start_y=" + start_y + "," +
- "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
- "user_info");
- return super.drag_end(evt,x,y,start_x,start_y,grab_x,grab_y,user_info);
- }
- }
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-